package com.mosai.alignpro.view;

import android.app.Dialog;
import android.content.Context;
import androidx.annotation.NonNull;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.mosai.alignpro.R;

/**
 * Created by Rays on 2020/11/25.
 */
public class AddAngleDialog extends Dialog implements View.OnClickListener {

    private OnAddListener onAddListener;

    public AddAngleDialog(@NonNull Context context, OnAddListener onAddListener) {
        super(context, R.style.AddDialog);
        setContentView(R.layout.add_angle_loading);
        this.onAddListener = onAddListener;
        findViewById(R.id.root).setOnClickListener(this);
        findViewById(R.id.llAddAngle).setOnClickListener(this);
        findViewById(R.id.llAddCircle).setOnClickListener(this);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.llAddAngle) {
            if (onAddListener != null) {
                onAddListener.onAdd(this, true);
            }
        } else if (v.getId() == R.id.llAddCircle) {
            if (onAddListener != null) {
                onAddListener.onAdd(this, false);
            }
        } else if (v.getId() == R.id.root) {
            dismiss();
        }
    }

    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        if (window == null) {
            return;
        }
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(layoutParams);
    }

    public interface OnAddListener {
        void onAdd(AddAngleDialog dialog, boolean isAngle);
    }
}
